/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TreeAction.java
 *
 * Created on 2010-11-7, 12:03:14
 */

package com.weed.components;

import com.weed.client.component.document.Item;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;

/**
 *
 * @author Jason
 */
public class TreeAction extends javax.swing.JPanel {

    /** Creates new form TreeAction */
    public TreeAction() {
        initComponents();
        this.defaultDataSrc1.submit(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        defaultDataSet1 = new com.weed.client.bind.DefaultDataSet();
        defaultDataSrc1 = new com.weed.client.bind.DefaultDataSrc();
        testDataSource1 = new com.weed.client.bind.TestDataSource();
        rScrollPane1 = new com.weed.client.component.ext.RScrollPane();
        rTree1 = new com.weed.client.component.RTree();
        rScrollPane2 = new com.weed.client.component.ext.RScrollPane();
        rCheckBoxTree1 = new com.weed.client.component.RCheckBoxTree();
        rLabel2 = new com.weed.client.component.ext.RLabel();
        rLabel3 = new com.weed.client.component.ext.RLabel();
        rTextField1 = new com.weed.client.component.RTextField();
        rTextField2 = new com.weed.client.component.RTextField();
        rTextField3 = new com.weed.client.component.RTextField();
        rTextField4 = new com.weed.client.component.RTextField();
        rScrollPane3 = new com.weed.client.component.ext.RScrollPane();
        rCheckBoxTree2 = new com.weed.client.component.RCheckBoxTree();

        defaultDataSrc1.setSource(testDataSource1);

        rScrollPane1.setHeaderText("单选树");

        rTree1.setDataSrc(defaultDataSrc1);
        rTree1.setSrcColumn("index:name:level:parentlevel");
        rTree1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                rTree1MouseClicked(evt);
            }
        });
        rScrollPane1.setViewportView(rTree1);

        rScrollPane2.setHeaderText("多选树");

        rCheckBoxTree1.setDataSet(null);
        rCheckBoxTree1.setDataSrc(defaultDataSrc1);
        rCheckBoxTree1.setSrcColumn("index:name:level:parentlevel");
        rCheckBoxTree1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                rCheckBoxTree1MouseClicked(evt);
            }
        });
        rScrollPane2.setViewportView(rCheckBoxTree1);

        rLabel2.setText("显示名称：");

        rLabel3.setText("显 示 值：");

        rTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rTextField1ActionPerformed(evt);
            }
        });

        rTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rTextField2ActionPerformed(evt);
            }
        });

        rTextField3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rTextField3ActionPerformed(evt);
            }
        });

        rTextField4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rTextField4ActionPerformed(evt);
            }
        });

        rScrollPane3.setHeaderText("多选树");

        rCheckBoxTree2.setDataSet(null);
        rCheckBoxTree2.setDataSrc(defaultDataSrc1);
        rCheckBoxTree2.setDoubleClick(true);
        rCheckBoxTree2.setSrcColumn("index:name:level:parentlevel");
        rCheckBoxTree2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                rCheckBoxTree2MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                rCheckBoxTree2MouseEntered(evt);
            }
        });
        rCheckBoxTree2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                rCheckBoxTree2KeyPressed(evt);
            }
        });
        rScrollPane3.setViewportView(rCheckBoxTree2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(rLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(rTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(rLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(rTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(37, 37, 37)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(rTextField4, javax.swing.GroupLayout.DEFAULT_SIZE, 295, Short.MAX_VALUE)
                            .addComponent(rTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(295, 295, 295))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(rScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(rScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 234, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE)
                    .addComponent(rScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE)
                    .addComponent(rScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void rTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rTextField1ActionPerformed

    private void rTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rTextField2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rTextField2ActionPerformed

    private void rTextField3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rTextField3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rTextField3ActionPerformed

    private void rTextField4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rTextField4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rTextField4ActionPerformed

    private void rTree1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rTree1MouseClicked
        // TODO add your handling code here:
     TreePath treePath = this.rTree1.getSelectionPath();
     if(treePath!=null){
       DefaultMutableTreeNode model = (DefaultMutableTreeNode)treePath.getPathComponent(treePath.getPathCount()-1);
       Item item = (Item)model.getUserObject();
       this.rTextField1.setText(item.getText());
       this.rTextField2.setText(String.valueOf(item.getValue()));
      }
    }//GEN-LAST:event_rTree1MouseClicked

    private void rCheckBoxTree1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rCheckBoxTree1MouseClicked
        // TODO add your handling code here:
        Object[] obj = this.rCheckBoxTree1.getSelectedObject();
        String text = new String();
        String value = new String();
        System.err.println(">>>>>>>>>>"+ obj.length +"::"+ obj);
        for (int i = 0; i < obj.length; i++) {
            Item item = (Item)obj[i];
            text = text + item.getText() + ",";
            value = value + item.getValue() + ",";
        }
        this.rTextField3.setText(text);
        this.rTextField4.setText(value); 
    }//GEN-LAST:event_rCheckBoxTree1MouseClicked

    private void rCheckBoxTree2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rCheckBoxTree2MouseClicked
        // TODO add your handling code here:
          Object[] obj = this.rCheckBoxTree2.getSelectedObject();
        String text = new String();
        String value = new String();
        System.err.println(">>>>>>>>>>"+ obj.length +"::"+ obj);
        for (int i = 0; i < obj.length; i++) {
            Item item = (Item)obj[i];
            text = text + item.getText() + ",";
            value = value + item.getValue() + ",";
        }
        this.rTextField3.setText(text);
        this.rTextField4.setText(value); 
    }//GEN-LAST:event_rCheckBoxTree2MouseClicked

    private void rCheckBoxTree2MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rCheckBoxTree2MouseEntered
        // TODO add your handling code here:
    }//GEN-LAST:event_rCheckBoxTree2MouseEntered

    private void rCheckBoxTree2KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_rCheckBoxTree2KeyPressed
        // TODO add your handling code here:
        Object[] obj = this.rCheckBoxTree2.getSelectedObject();
        String text = new String();
        String value = new String();
        System.err.println(">>>>>>>>>>"+ obj.length +"::"+ obj);
        for (int i = 0; i < obj.length; i++) {
            Item item = (Item)obj[i];
            text = text + item.getText() + ",";
            value = value + item.getValue() + ",";
        }
        this.rTextField3.setText(text);
        this.rTextField4.setText(value);
    }//GEN-LAST:event_rCheckBoxTree2KeyPressed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private com.weed.client.bind.DefaultDataSet defaultDataSet1;
    private com.weed.client.bind.DefaultDataSrc defaultDataSrc1;
    private com.weed.client.component.RCheckBoxTree rCheckBoxTree1;
    private com.weed.client.component.RCheckBoxTree rCheckBoxTree2;
    private com.weed.client.component.ext.RLabel rLabel2;
    private com.weed.client.component.ext.RLabel rLabel3;
    private com.weed.client.component.ext.RScrollPane rScrollPane1;
    private com.weed.client.component.ext.RScrollPane rScrollPane2;
    private com.weed.client.component.ext.RScrollPane rScrollPane3;
    private com.weed.client.component.RTextField rTextField1;
    private com.weed.client.component.RTextField rTextField2;
    private com.weed.client.component.RTextField rTextField3;
    private com.weed.client.component.RTextField rTextField4;
    private com.weed.client.component.RTree rTree1;
    private com.weed.client.bind.TestDataSource testDataSource1;
    // End of variables declaration//GEN-END:variables

}
